/* eslint-disable eol-last */
/* eslint-disable indent */
'use strict';

module.exports = app => {
    // 获取数据类型
    const { STRING, INTEGER } = app.Sequelize;
    // 建模,创建的表 users 自动加的s
    // eslint-disable-next-line no-unused-vars
    const User = app.model.define('user', {
        // 自动创建id，createAt，updateAt
        userName: {
            type: STRING,
            unique: true,
            allowNull: false,
            comment: '用户名，唯一，不能为空',
        },
        password: {
            type: STRING,
            allowNull: false,
            comment: '密码',
        },
        nickName: {
            type: STRING,
            comment: '昵称',
        },
        gender: {
            type: INTEGER,
            allowNull: false,
            defaultValue: 1,
            comment: '性别(1->男 2->女 3->保密)',
        },
        avatar: {
            type: STRING,
            comment: '头像，图片的地址',
        },
        city: {
            type: STRING,
            allowNull: false,
            defaultValue: '秦皇岛',
            comment: '城市',
        },
    });
    // 创建连接关系
    User.associate = () => {
        app.model.User.hasMany(app.model.Blog, {
            foreignKey: 'userId',
            targetKey: 'id',
        });
        app.model.User.hasMany(app.model.UserRelation, {
            foreignKey: 'userId',
        });
    };
    return User;
};